﻿#include "etl/array.h"
#include "etl/circular_buffer.h"
#include "etl/deque.h"
#include "etl/byte_stream.h"

#include <vector>
#include <array>

#define FMT_HEADER_ONLY
#define FMT_UNICODE 0
#include <fmt/core.h>
#include <fmt/ranges.h>

static const size_t SIZE = 10UL;

typedef etl::array<int, SIZE> Data;
typedef etl::deque<int, SIZE*2> DataInt;

using DataM = etl::circular_buffer<uint8_t, SIZE>;

int main()
{
    Data data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

    for (auto b : data)
    {
        fmt::println("{}", b);
    }
    fmt::println("----");

    DataM    datam;

    for (uint32_t i = 0U; i < SIZE; ++i)
    {
        datam.push(i+1);
    }
    for (auto b : datam)
    {
        fmt::println("{}", b);
    }
    fmt::println("----");
    std::vector<int> int_data1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
    std::vector<int> int_data2 = {15, 16, 17, 18};

    DataInt data_int(int_data1.begin(), int_data1.end());
    data_int.pop_front();
    data_int.pop_front();
    data_int.pop_front();
    data_int.pop_front();
    data_int.insert(data_int.end(), int_data2.begin(), int_data2.end());
    for (auto b : data_int)
    {
        fmt::println("{}", b);
    }

    fmt::println("----");
    std::array<char, sizeof(uint32_t) * 4> storage;
    std::array<char, sizeof(uint32_t) * 4> compare_data = { char(0x12), char(0x34), char(0x56), char(0x78),
                                                            char(0x55), char(0xAA), char(0x5A), char(0xA5),
                                                            char(0xA5), char(0x5A), char(0x5A), char(0xA5),
                                                            char(0xFF), char(0xFF), char(0xFF), char(0xFF) };


    etl::byte_stream_writer byte_stream(storage.data(), storage.size(), etl::endian::big);

    (byte_stream.write(uint32_t(0x12345678U)));
    (byte_stream.write(uint32_t(0x55AA5AA5U)));
    (byte_stream.write(uint32_t(0xA55A5AA5U)));
    (byte_stream.write(uint32_t(0xFFFFFFFFU)));

    for (size_t i = 0U; i < storage.size(); ++i)
    {
        if (int(compare_data[i]) != int(storage[i]))
        {
            fmt::println("failed.");
            break;
        }
    }
}

